import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:spotify_plugin_t/spotify_plugin_t.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

  @override
  void initState() {
    super.initState();
  }

  //获取spotify code
  getSpotifyCode() async {
    //11:F7:87:30:10:86:66:8F:AA:B3:47:99:4D:85:C5:58:25:1D:32:21

    String scope =
        "ugc-image-upload,user-read-playback-state,user-read-currently-playing,playlist-read-private,playlist-read-collaborative,playlist-modify-private,playlist-modify-public,user-follow-modify,user-follow-read,user-read-playback-position,user-top-read,user-read-recently-played,user-library-modify,user-library-read,user-read-email,user-read-private";
    String? code = await SpotifyPlugin_t.getSpotifyCode(
        clientId: "49b70ef6a5e24167a4cdc5504fc4ac5a",
        url: "spotify-shengguanyang://auth",
        scope: scope); //spotify-sdk://auth
    print("code = $code");
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: GestureDetector(
            onTap: (){
              getSpotifyCode();
            },
            child: Container(
              padding: EdgeInsets.symmetric(horizontal: 20,vertical: 20),
              color: Colors.pink,
              child: Text("点我"),
            ),
          ),
        ),
      ),
    );
  }
}
